/**
 * Created by Administrator on 2017/7/31.
 */
$(function() {
    var goods_id = getQueryString("goods_id");
    var key = getCookie('key');
    $.ajax({
        url: ApiUrl + "/index.php?act=goods&op=pdinfo",
        data: {goods_id: goods_id},
        type: "get",
        dataType:"json",
        success: function(result) {
            $(".fixed-tab-pannel").html(result.datas.prodinfo.pgoods_body);
        }
    });

    /**
     * 立即购买
     */
    $("#buy-now").click(function(){
        //渲染页面
        $.ajax({
            url: ApiUrl + "/index.php?act=goods&op=pdinfo",
            type: "get",
            data: {goods_id: goods_id, key: key},
            dataType: "json",
            success: function (result) {
                data = result.datas;
                if(!key){
                    window.location.href = WapSiteUrl+'/tmpl/member/login.html';
                }else{
                    var buynum = 1;
                    if (buynum < 1) {
                        $.sDialog({
                            skin:"red",
                            content:'参数错误！',
                            okBtn:false,
                            cancelBtn:false
                        });
                        return;
                    }
                    if (buynum > data.prodinfo.goods_storage) {
                        $.sDialog({
                            skin:"red",
                            content:'库存不足！',
                            okBtn:false,
                            cancelBtn:false
                        });
                        return;
                    }
                    var json = {};
                    json.key = key;
                    json.is_point = 1;
                    json.cart_id = goods_id+'|'+buynum;
                    $.ajax({
                        type:'post',
                        url:ApiUrl+'/index.php?act=member_buy&op=buyPoint_step',
                        data:json,
                        dataType:'json',
                        success:function(result){
                            console.log(result);
                            if (result.datas.error) {
                                $.sDialog({
                                    skin:"red",
                                    content:result.datas.error,
                                    okBtn:false,
                                    cancelBtn:false
                                });
                            }else{
                                location.href = WapSiteUrl+'/tmpl/order/point_buy_setp.html?goods_id='+goods_id+'&buynum='+buynum+"&is_point=1";
                            }
                        }
                    });
                }
            }
        })
    })

    $('#goodsDetail').click(function(){
        window.location.href = WapSiteUrl+'/tmpl/pd_details.html?goods_id=' + goods_id;
    });
    $('#goodsBody').click(function(){
        window.location.href = WapSiteUrl+'/tmpl/pd_detailsInfo.html?goods_id=' + goods_id;
    });
    $('#goodsEvaluation').click(function(){
        window.location.href = WapSiteUrl+'/tmpl/product_eval_list.html?goods_id=' + goods_id;
    });
});